import React, { Component } from 'react'

export default class App extends Component {
  constructor() {
    super()
    this.handleClick = this.handleClick.bind(this)
  }
  state = {
    msg: 'hello react'
  }
  render() {
    return (
      <div>
        <h1>App</h1>
        <button onClick={this.handleClick}>点我</button>
        <br />
        <button onClick={this.handleClick.bind(this)}>1. 使用bind改变this的指向</button>
        <br />
        <button onClick={(e) => this.handleClick(e, 1)}>2. 使用箭头函数处理</button>
        <br />
        <button onClick={this.handleClick}>3. 在构造函数中改变this的指向</button>
        <br />
        <button onClick={this.handleClick}>4. 以箭头函数定义方法</button>
      </div>
    )
  }

  handleClick(e, number) {
    console.log(e, number)
    // console.log('点我')
    // console.log(this.state.msg)
    // console.log(this)
  }
  // handleClick = () => {
  //   console.log(this.state.msg)
  // }
}
